<template>
  <div class="dialog">
    <el-dialog :title="title" :visible.sync="visible" :close-on-click-modal="false" width="65%">
      <el-form :model="createForm" label-width="120px" label-suffix=":" ref="createForm">
        <div class="page-panel-title" style="margin-top: 0">客户信息</div>
        <div class="page-panel">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="养护单名称" prop="name">
                <el-input v-model.trim="createForm.name" placeholder="请点击图标选择养护单" readonly>
                  <i v-if="!readonly" slot="prefix" class="el-input__icon el-icon-search"
                     @click="onSearchCustom"></i></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="养护单编号" prop="masterNo">
                <el-input v-model.trim="createForm.masterNo" placeholder="" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="退货原因" prop="conserveMemo">
                <el-input v-model.trim="createForm.reason" placeholder="请输入退货原因" :readonly="readonly"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeNetWorker()">关 闭</el-button>
        <el-button v-if="!readonly" type="primary" @click="confirmData('createForm')">保 存</el-button>
      </div>
      <master-dialog ref="customer" @ok="customerOk"></master-dialog>
    </el-dialog>
  </div>
</template>
<script>
import {
  addApply
} from '@/api/businessExtend'
import MasterDialog from './MasterDialog'
export default {
  name: 'StoreOrderReturnApplyDialog',
  components: {
    MasterDialog
  },
  data () {
    return {
      title: '养护单退货申请',
      visible: false,
      readonly: false,
      createForm: {},
      goodsList: [],
    }
  },
  created () { },
  mounted () { },
  methods: {
    add () {
      // const table = this.$refs.xTable;
      // if (table) {
      //   table.remove();
      // }
      this.readonly = false;
      this.title = "新增";
      this.createForm = {};
      this.init();
      this.visible = true;
    },
    edit (val) {
      this.createForm = Object.assign({}, val)
      this.initGoods()
      this.visible = true
    },
    initGoods () {
      storeOrderReturnDetail({ id: this.createForm.id }).then((res) => {
        if (res.data.code == 0) {
          this.goodsList = res.data.data
        }
      }
      )
    },
    init () {
    },
    onSearchCustom () {
      this.$refs.customer.select();
    },
    customerOk (val) {
      this.createForm.customId = val.id;
      this.$set(this.createForm, "name", val.name);
      this.$set(this.createForm, "masterNo", val.docNo);
    },
    confirmData (formData) {
      this.$refs[formData].validate((valid) => {
        if (valid) {
          if (this.createForm.id) {

          } else {
            console.log('this.createForm', this.createForm)
            addApply(this.createForm).then((res) => {
              const data = res.data
              if (data.code == 0) {
                this.$message.success('新增成功');
                this.$emit('ok');
                this.closeNetWorker();
              } else {
                this.$message.error(data.data || '新增失败')
              }
            })
          }
        }
      });
    },
    closeNetWorker () {
      this.createForm = {}
      this.goodsList = []
      this.visible = false
    }
  }
}
</script>
<style scoped lang="less"></style>
